import { LoggerUtility } from '../logger/logger.utility';
import { Utility } from '../utility/utility';
// tslint:disable:object-literal-shorthand
// tslint:disable:space-before-function-paren
const injector = {
    register: function (handler) {
        this.storage[handler.key] = handler;
    },
    resolve: function (key) {
        if (this.storage[key]) {
            const instance = new this.storage[key]();
            // tslint:disable-next-line:no-unused-expression
            // instance.apply && instance.apply(para);
            return instance;
        } else {
            LoggerUtility.error('injector.resolve: cant resolve key - ' + key, undefined);
            throw new Error('injector.resolve: cant resolve key - ' + key);
        }
    },
    storage: {},
};

export class Injector {
    public static create(): { storage: any, register: (handler) => void, resolve: (key) => any } {
        return Utility.deepCloneObjWithFun(injector);
    }
}
